/**
 * 
 */
package any.gwt.client.util;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO: Doc me
 * 
 * @author keke <keke@codehaus.org>
 * @version
 * @revision $Revision:$
 */
public class EventDispatcher {
    private List listeners;

    public void addDispatcherListener(final DispatcherListener listener) {
        if (listeners == null) {
            listeners = new ArrayList();
        }
        listeners.add(listener);
    }

    public void dispatch(final DispatchEvent event) {
        if (listeners != null) {
            for (int i = 0; i < listeners.size(); i++) {
                if (event.isConsumed()) {
                    break;
                }
                ((DispatcherListener) listeners.get(i))
                        .fireDispatchEvent(event);
            }
        }
    }

    public void removeDispatcherListener(final DispatcherListener listener) {
        if (listeners != null) {
            listeners.remove(listener);
        }
    }
}
